﻿package com.game.module.semiInterface
{
	import com.game.event.GameEvent;
	import com.game.manager.GameSceneManager;
	import com.game.manager.NotificationManager;
	
	import config.Config;
	
	import flash.display.MovieClip;
	import flash.display.SimpleButton;
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.events.MouseEvent;
	
	public class ChaosDoor extends Sprite
	{
		
		public function ChaosDoor()
		{
			super();
			this.gc = Config.getIns();
			this.addEventListener(Event.ADDED_TO_STAGE, this.added, false, 0, true);
			this.addEventListener(Event.REMOVED_FROM_STAGE, this.removed, false, 0, true);
		}
		
		public var dupbtn:SimpleButton;
		
		public var worbtn:SimpleButton;
		
		public var xbtn:SimpleButton;
		
		public var pastbtn:SimpleButton;
		
		public var csmc:MovieClip;
		private var gc:Config;
		
		private function destroy():void
		{
			if (this.parent)
			{
				this.parent.removeChild(this);
			}
		}
		
		private function added(param1:Event):void
		{
			this.dupbtn.addEventListener(MouseEvent.CLICK, this.intoDefendDuplicate);
			this.worbtn.addEventListener(MouseEvent.CLICK, this.intoNewWorld);
			this.pastbtn.addEventListener(MouseEvent.CLICK, this.pastClick);
			this.xbtn.addEventListener(MouseEvent.CLICK, this.xClick);
			if (this.gc.userData.lastWorld == 0)
			{
				this.csmc.gotoAndStop(1);
			}
			else
			{
				this.csmc.gotoAndStop(2);
			}
		}
		
		private function removed(param1:Event):void
		{
			this.dupbtn.removeEventListener(MouseEvent.CLICK, this.intoDefendDuplicate);
			this.worbtn.removeEventListener(MouseEvent.CLICK, this.intoNewWorld);
			this.pastbtn.removeEventListener(MouseEvent.CLICK, this.pastClick);
			this.xbtn.removeEventListener(MouseEvent.CLICK, this.xClick);
		}
		
		private function pastClick(param1:MouseEvent):void
		{
			GameSceneManager.getIns().addScene(new ToThePast());
			this.parent.removeChild(this);
		}
		
		private function intoDefendDuplicate(param1:MouseEvent):void
		{
			if (gc.playerData.level < 50)
			{
				NotificationManager.alert("玩家的等级必须都大于50级才可以进入");
				return;
			}
			this.gc.curStage = 116;
			this.gc.curLevel = 1;
			this.destroy();
		}
		
		private function intoNewWorld(param1:MouseEvent):void
		{
			if(gc.playerData.getStuffNumByName("ttlp") < 1)
			{
				NotificationManager.alert("需要通天令牌!");
				
			}
			if (this.gc.userData.lastWorld == 0)
			{
				GameSceneManager.getIns().showGameMap(GameSceneManager.MAP_NEW_WORLD);
			}
			else
			{
				GameSceneManager.getIns().showGameMap(GameSceneManager.MAP_PARADISE);
			}
			this.destroy();
		}
		
		private function xClick(param1:MouseEvent):void
		{
			this.destroy();
		}
	}
}
